from util import *

def createRssItem(title, link, desc, pubdate):
    return RSS_ITEM % {'itemtitle': title,
                       'itemlink': link,
                       'itemdesc': desc,
                       'itempubdate': pubdate if type(pubdate) is str else Util.toDateTimeStr(pubdate)
                       }

def createRss(title, link, desc, items):
    return RSS_MASTER % {'sitetitle': title,
                         'sitelink': link,
                         'sitedesc': desc,
                         'items': ''.join(items)
                         }

RSS_MASTER = '''<?xml version="1.0"?>
<rss version="2.0"> 
   <channel> 
      <title>%(sitetitle)s</title> 
      <link>%(sitelink)s</link> 
      <description>%(sitedesc)s</description> 
      <language>en-us</language>
      %(items)s
   </channel> 
</rss>
'''

RSS_ITEM = '''<item>
<title>%(itemtitle)s</title>
<link>%(itemlink)s</link>
<description>%(itemdesc)s</description>
<pubDate>%(itempubdate)s</pubDate>
</item>
'''